﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Pool{
   
    Queue<GameObject> queue = new Queue<GameObject>();
     GameObject prefab;

    public void Init(GameObject _prefab)
    {
        prefab = _prefab;
    }
	// Use this for initialization
	void Start () {
	
	}
	public GameObject Get()
    {
        GameObject go = null;
        if (queue.Count==0)
        {
            go = Object.Instantiate(prefab);
            go.name = prefab.name;
        }
        else
        {
            go = queue.Dequeue();
            
        }
        go.SetActive(true);
        go.transform.SetParent(null);
        
        return go;
    }
	public void Save(GameObject go)
    {
        go.SetActive(false);
        go.transform.position = Vector3.zero;
        queue.Enqueue(go);
    } 
}
